package tp.pr5;

/**
 * An enum class that represents the compass directions (North, east, south and west) plus a value that represents an unknown direction.
 *
 */
public enum Direction 
{
	
	NORTH, EAST, SOUTH, WEST, UNKNOWN; 

	/**
	 * return the right direction
	 * 
	 * @return Direction
	 */
	public Direction rotateRight()
	{
		Direction[] direction = Direction.values();
		
		int right = (this.ordinal() + 1) % 4;
		
		return direction[right];
	}
	
	/**
	 * return the left direction
	 * 
	 * @return Direction
	 */
	public Direction rotateLeft()
	{
		Direction[] direction = Direction.values();
		int left = 3;
		
		if(this.ordinal() - 1 >= 0)
		{
			left = (this.ordinal() - 1 ) % 4;
		}
		
		return direction[left];
	}
	
	/**
	 * return the opposite Direction
	 * 
	 * @return Direction
	 */
	public Direction opposite()
	{
		Direction[] direction = Direction.values();
		int opposite;
		
		if(this.ordinal() - 2 < 0)
		{
			opposite = this.ordinal() + 2;
		} 
		else 
		{
			opposite = this.ordinal() - 2;
		}
		
		return direction[opposite];
	}	
	
}
